package com.afterRain.interceptor;

import com.afterRain.commonly.CommonlyRecord;
import com.afterRain.commonly.UrlRecord;
import com.afterRain.model.Admin;
import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;

/**
* @author 作者 E-mail:
* @version 创建时间：2017年5月9日 下午3:06:12
* 类说明
*/
public class UserInterceptor implements Interceptor{

	public void intercept(Invocation inv) {
		Controller controller = inv.getController();
		Admin admin = (Admin) controller.getSession().getAttribute(CommonlyRecord.SESSION_USER.name());
		if(admin ==null){
			controller.setAttr("request", controller.getRequest());
			controller.redirect(UrlRecord.URL_REDIRECT_LOGIN);
			return;
		}
		inv.invoke();
		controller.setAttr("request", controller.getRequest());
		controller.setAttr("admin", controller.getSessionAttr(CommonlyRecord.SESSION_USER.name()));
	}

}
